<?php

namespace App\Providers;

use App\Lib\Auth\FLAuth;
use App\Lib\Contracts\FLAuth as FLAuthContract;
use App\Lib\Logs\Logs;
use App\Modules\Employee\Services\AuthService;
use Flower\Core\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
	/**
	 * Bootstrap any application services.
	 *
	 * @return void
	 */
	public function boot()
	{
//异常重新接入laravel异常处理机制中
		app('api.exception')->register(function (\Exception $exception) {
			$request = Request::capture();
			return app('app\Exceptions\Handler')->render($request, $exception);
		});
		Logs::sqlInfo(true);
	}

	/**
	 * Register any application services.
	 *
	 * @return void
	 */
	public function register()
	{
		$this->app->register(RepositoryServiceProvider::class);

		$this->registerClassAliases();

		$this->registerAuth();
	}

	/**
	 * Register the class aliases.
	 *
	 * @return void
	 */
	protected function registerClassAliases()
	{
		$serviceAliases = [
			'flower.core.auth' => FLAuthContract::class
		];
		foreach ($serviceAliases as $key => $aliases) {
			foreach ((array)$aliases as $alias) {
				$this->app->alias($key, $alias);
			}
		}
	}

	public function registerAuth()
	{
		$this->app->singleton('flower.core.auth', function ($app) {
			return new FLAuth($app->make(AuthService::class));
		});

	}
}
